
function getUserInfo() {
  return new Promise((resolve, reject) => {
    BOT.getUserInfo({
      success: res => {
        console.log(res.data);
        resolve(res.data)
      },
      fail: res => {
        Toast('Failed to get user information.');
        reject();
      }
    })
  })
}

function auth() {
  return new Promise((resolve, reject) => {
    BOT.getAuthcode({
      state: '',
      scope: '',
      redirectUri: 'https://botim.me/mp/b/?app=me.botim.demo.game'
    }, {
      success: function (res) {
        resolve(res.data);
      },
      fail: function(err) {
        reject();
      }
    })
  })
}

async function authClickHandler() {
	console.log("===authClickHandler===")
  await auth();
  const user = await getUserInfo();
  const contaner = document.querySelector('#user');
  contaner.innerHTML = '';
  for (const [key, value] of Object.entries(user)) {
    const div = document.createElement('div');
    div.classList.add('use-item')
    div.innerHTML = `
      <span>${key}:</span>
      <span>${JSON.stringify(value)}</span>
    `;
    contaner.appendChild(div);
  }
}

